package com.bytz.modules.cms.domain.model.order;

import com.bytz.modules.cms.order.model.OrderModel;
import com.bytz.modules.cms.product.model.ProductModel;
import com.bytz.modules.cms.productLine.entity.ProductLine;
import com.bytz.modules.cms.user.entity.CmsSysUser;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author shanxuezhong
 */
@Getter
@Setter
@EqualsAndHashCode
public class MallOrderProcessContext {

    /**
     * 订单
     */
    private OrderModel order;

    /**
     * 经销商Id
     */
    private String resellerId;

    /**
     * 是否为标准订单
     */
    private Boolean standardOrder;

    /**
     * 是否为项目订单
     */
    private Boolean projectOrder;

    /**
     * 买的产品编号
     */
    private Set<String> productNumbers = Collections.emptySet();

    /**
     * 买的产品
     */
    private Map<String, ProductModel> productModelMap = Collections.emptyMap();


    /**
     * 销售
     */
    private CmsSysUser seller;

    /**
     * 销售所在产品线
     */
    private ProductLine sellerProductLine;
    /**
     * 是否为提交
     */
    private Boolean submit;

    public void setProductModel(Collection<ProductModel> productModels) {
        if (CollectionUtils.isNotEmpty(productModels)) {
            this.productModelMap = productModels.stream().collect(Collectors.toMap(ProductModel::getProductNumber, Function.identity()));
        }
    }

    public Collection<ProductModel> getProducts() {
        return productModelMap.values();
    }

}